//
//  ChipDetailViewController.m
//  CarPark
//
//  Created by oceans on 2019/8/4.
//  Copyright © 2019 oceans. All rights reserved.
//

#import "ChipDetailViewController.h"
#import "DetailTextCollectionViewCell.h"

@interface ChipDetailViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (strong, nonatomic) UICollectionView *collection;
@property (strong, nonatomic) NSDictionary *info;
@end

@implementation ChipDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self loadData];
}

- (void)loadData {
    
    defweakself
    [HttpRequest getURL:[NSString stringWithFormat:kchip_detail, __id] paras:nil showProgress:NO successful:^(id  _Nullable result) {
        NSLog(@"%@", result);
        weakself.info = result[@"datas"];
        [weakself setupView];
    } failed:^(int code, NSString * _Nullable errMsg) {
        
    }];
}

- (void)setupView {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 0.0;
    layout.itemSize = CGSizeMake(ScreenWidth, 45.0);
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, XNavigationHeight, ScreenWidth, ScreenHeight-XNavigationHeight) collectionViewLayout:layout];
    _collection.backgroundColor = [UIColor whiteColor];
    _collection.delegate = self;
    _collection.dataSource = self;
    [self.view addSubview:_collection];
    [_collection registerNib:[UINib nibWithNibName:@"DetailTextCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"DetailTextCollectionViewCell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DetailTextCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DetailTextCollectionViewCell" forIndexPath:indexPath];
    if (indexPath.item == 0) {
        cell.leftLabel.text = @"状态";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"monitor_status_text"]];
    }else if (indexPath.item == 1) {
        cell.leftLabel.text = @"状态更新时间";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"updated_at"]];
    }else if (indexPath.item == 2) {
        cell.leftLabel.text = @"芯片所属";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"monitor_company"][@"name"]];
    }else if(indexPath.item == 3) {
        cell.leftLabel.text = @"芯片启用时间";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"start_at"]];
    }else if(indexPath.item == 4) {
        cell.leftLabel.text = @"所在停车场";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"parking"][@"name"]];
    }else if(indexPath.item == 5) {
        cell.leftLabel.text = @"安装人";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"task_chipinstall"][@"staff_name"]];
    }else if(indexPath.item == 6) {
        cell.leftLabel.text = @"安装性质";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"task_chipinstall"][@"install_type"]];
    }else if(indexPath.item == 7) {
        cell.leftLabel.text = @"绑定车辆";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"autocar"][@"car_model"]];
    }else if(indexPath.item == 8) {
        cell.leftLabel.text = @"车架号";
        cell.rightLabel.text = [NSString stringWithFormat:@"%@", _info[@"autocar"][@"vin_no"]];
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
}

@end
